package eleme.openapi.sdk.oauth.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author me
 */
public class ServerOAuthCodeImpl {

    private String serverUrl;
    private String appKey;

    public ServerOAuthCodeImpl(String serverUrl, String appKey) {
        this.serverUrl = serverUrl;
        this.appKey = appKey;
    }

    public String getAuthUrl(String redirectUri,
            String scope,
            String state) {
        String responseType = "code";
        try {
            redirectUri = URLEncoder.encode(redirectUri, "utf-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        return String.format("%s?response_type=%s&client_id=%s&state=%s&redirect_uri=%s&scope=%s", serverUrl, responseType, appKey, state, redirectUri, scope);
    }

}
